package sketch.seg.cd.exp;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.List;

import sketch.doc.Sketch;
import sketch.doc.SketchContainer;
import sketch.ink.SampledPoint;
import sketch.ink.Stroke;
import sketch.seg.cd.CDStaticKH;

public class RelativeRhoPrinter {

	public static final int MIN_K = 1;

	public static final int MAX_K = 20;

	private String inputFileName;

	private String outputFileName;

	private int K;

	public RelativeRhoPrinter(int k, String filename) {
		inputFileName = filename;
		K = k;
		outputFileName = inputFileName + ".k" + K;
	}

	public void output() {

		try {
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outputFileName))));

			Sketch sketch = SketchContainer.get().open();
			sketch.readFromFile(new File(inputFileName));

			Stroke s = sketch.getStrokes().get(0);
			List<SampledPoint> list = s.getPoints();
			SampledPoint[] ps = new SampledPoint[list.size()];
			list.toArray(ps);

			for (int i = 0; i < ps.length; i++) {
				bw.write(Double.toString(CDStaticKH.relativeRho(ps, i, K)));
				bw.write("\n");
			}

			bw.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {
		String prefix = "./exp/zhengwt/zhengwt.seg.";
		for (int i = 1; i <= 20; i++) {
			String input = prefix + Integer.toString(i);
			for (int j = MIN_K; j <= MAX_K; j++) {
				new RelativeRhoPrinter(j, input).output();
			}
		}
	}

}
